//
//  CYBaseViewController.swift
//  MySina
//
//  Created by mac on 2017/1/17.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit

class CYBaseViewController: UIViewController {

    //判断是否登录
    let isLogin: Bool = false
    //定义方可视图
    var baseView: CYBaseView?
    
    override func loadView() {
        //登录进入视图列表
        if isLogin {
//            super.loadView()
            view = UITableView()
        } else {
            //未登录进入未登录状态
            setupBaseView()
        }
    }
    private func setupBaseView() {
        setupNavgationView()
        baseView = CYBaseView()
        
        //闭包调用
        baseView?.closure = {[weak self] in
            //调用本类中的注册和登录方法
            self?.buttonClick()
        }
        
        view = baseView
        
    }
    //设置导航
    private func setupNavgationView() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "登录", target: self, action: #selector(buttonClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", target: self, action: #selector(buttonClick))
        
    }
    
    //四个按钮联动 注册和登录按钮
    @objc private func buttonClick() {
    //创建控制器
        let oauthVC = CYOAuthViewController()
        //present控制器
        self.present(CYMainNavigationController(rootViewController: oauthVC), animated: true, completion: nil)
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}
